package com.fwj.core.common.model;

import com.alibaba.fastjson.JSONObject;


/**
 * @Author: fwj
 * @Data: 2021/12/17 14:20
 * @Version 1.0
 * @Description:
 */


public class ResponseDTO<T> extends JSONObject {
    private static final String CODE = "code";
    private static final String EXPLANATION = "explanation";
    private static final String DATA = "data";
    private static final String MESSAGE = "message";

    public ResponseDTO() {
    }

    public ResponseDTO(int code) {
        super.put(CODE,code);
    }

    public ResponseDTO(int code,String massage) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
    }

    public ResponseDTO(int code,String massage,String explanation) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
        super.put(EXPLANATION,explanation);
    }

    public ResponseDTO success() {
        super.put(CODE, ResponseEnum.SUCCESS.getCode());
        super.put(MESSAGE,ResponseEnum.SUCCESS.getMessage());
        super.put(EXPLANATION,ResponseEnum.SUCCESS.getExplanation());
        return this;
    }

    public ResponseDTO success(int code) {
        super.put(CODE,code);
        return this;
    }

    public ResponseDTO success(int code,String massage) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
        return this;
    }

    public ResponseDTO success(int code,String massage,String explanation) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
        super.put(EXPLANATION,explanation);
        return this;
    }

    public ResponseDTO fail() {
        super.put(CODE, ResponseEnum.SERVER_ERROR.getCode());
        super.put(MESSAGE,ResponseEnum.SERVER_ERROR.getMessage());
        super.put(EXPLANATION,ResponseEnum.SERVER_ERROR.getExplanation());
        return this;
    }

    public ResponseDTO fail(int code) {
        super.put(CODE,code);
        return this;
    }

    public ResponseDTO fail(int code,String massage) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
        return this;
    }

    public ResponseDTO fail(int code,String massage,String explanation) {
        super.put(CODE,code);
        super.put(MESSAGE,massage);
        super.put(EXPLANATION,explanation);
        return this;
    }

    public ResponseDTO(ResponseEnum responseEnum) {
        if (responseEnum != null) {
            super.put(CODE, responseEnum.getCode());
            super.put(MESSAGE, responseEnum.getMessage());
            super.put(EXPLANATION, responseEnum.getExplanation());
        }
    }

    public ResponseDTO success(ResponseEnum responseEnum){
        if (responseEnum!=null){
            super.put(CODE,responseEnum.getCode());
            super.put(MESSAGE,responseEnum.getMessage());
            super.put(EXPLANATION,responseEnum.getExplanation());
        }
        return this;
    }

    public ResponseDTO fail(ResponseEnum responseEnum){
        if (responseEnum!=null){
            super.put(CODE,responseEnum.getCode());
            super.put(MESSAGE,responseEnum.getMessage());
            super.put(EXPLANATION,responseEnum.getExplanation());
        }
        return this;
    }

    public ResponseDTO setData(T data){
        super.put(DATA,data);
        return this;
    }
}
